package org.one.afternoon.common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    /**
     * 利用MyBatisPlus的MetaObjectHandler接口实现属性插入时自动填充
     * @param metaObject 元对象
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start info fill......");
        this.setFieldValByName("createAt",new Date(),metaObject);
        this.setFieldValByName("updateAt",new Date(),metaObject);
        this.setFieldValByName("language","中文",metaObject);
    }

    /**
     * 利用MyBatisPlus的MetaObjectHandler接口实现属性修改时自动填充
     * @param metaObject 元对象
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start info fill......");
        this.setFieldValByName("updateAt",new Date(),metaObject);
    }
}
